﻿Imports System.Collections.Specialized
Imports System.Windows.Forms

Public Class CrashToCrash
    Public Overrides Function DoAddCheck() As Boolean
        DoAddCheck = False
        Me.ValidateChildren()
        If Me.txtTitle.Text.Trim = String.Empty Then
            ShowMessageBox("冲账原因不能为空")
            Me.txtTitle.Focus()
            Exit Function
        End If

        'If numUpDown.Value <= 0 Then
        '    ShowMessageBox("冲账不能小于0")
        '    Me.numUpDown.Focus()
        '    Exit Function
        'End If

        If Me.txtUsername.Text.Trim = String.Empty Then
            ShowMessageBox("冲账用户不能为空")
            Me.btnUsername.Focus()
            Exit Function
        End If

        If chk是否启用关联更新.Checked Then
            If numUpDown.Value <> Me.NM冲账关联金额1.Value + Me.NM冲账关联金额2.Value + Me.NM冲账关联金额3.Value + Me.NM冲账关联金额4.Value Then
                If ShowMessageResult("关联金额与冲账金额不相等,是否继续？") = Windows.Forms.DialogResult.No Then
                    Me.NM冲账关联金额1.Focus()
                    Exit Function
                End If
            End If
        End If
        DoAddCheck = True
    End Function

    Public Overrides Function DoAddExist() As Boolean
        Return True
    End Function

    Public Sub ClearForm()
        Me.txtTitle.Text = ""

        Me.numUpDown.Value = 0
        Me.dt1.Value = Now
        Me.txtMemo.Text = ""

        Me.txt冲账关联1.Text = ""
        Me.txt冲账关联1.Tag = ""

        Me.txt冲账关联2.Text = ""
        Me.txt冲账关联2.Tag = ""

        Me.txt冲账关联3.Text = ""
        Me.txt冲账关联3.Tag = ""

        Me.txt冲账关联4.Text = ""
        Me.txt冲账关联4.Tag = ""

        NM冲账关联金额1.Value = 0
        NM冲账关联金额2.Value = 0
        NM冲账关联金额3.Value = 0
        NM冲账关联金额4.Value = 0

    End Sub

    Public Overrides Sub InitAdd()
        ClearForm()
    End Sub

    Public Overrides Function DoInsert() As Boolean
        MyBase.DoInsert()
        DoInsert = False
        Dim cmd As New ADODB.Command
        Dim sb As New StringBuilder
        sb.AppendLine(" Insert Into ")
        sb.AppendLine(" CrashToCrash ")
        sb.AppendLine(" (")
        sb.AppendLine(" Title ")
        sb.AppendLine(" ,Count ")
        sb.AppendLine(" ,DateTime ")
        sb.AppendLine(" ,Memo ")
        sb.AppendLine(" ,UserName ")
        sb.AppendLine(" ,OPTIME ")
        sb.AppendLine(" ,id ")
        sb.AppendLine(" ) ")
        sb.AppendLine(" Values ")
        sb.AppendLine(" ( ")
        sb.AppendLine(" ? ")
        sb.AppendLine(" ,? ")
        sb.AppendLine(" ,? ")
        sb.AppendLine(" ,? ")
        sb.AppendLine(" ,? ")
        sb.AppendLine(" ,? ")
        sb.AppendLine(" ,? ")
        sb.AppendLine(" ) ")
        Dim pa As ADODB.Parameter
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput)
        If CMainModule.CmnToStr1(Me.txtTitle.Text).Trim().Length > 0 Then
            pa.Size = CMainModule.CmnToStr1(Me.txtTitle.Text).Trim().Length
        Else
            pa.Size = 10
        End If
        pa.Value = CMainModule.CmnToStr1(Me.txtTitle.Text).Trim()
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDecimal, ADODB.ParameterDirectionEnum.adParamInput)
        pa.Value = numUpDown.Value
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, dt1.Value.ToString)
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, Me.txtMemo.Text.Trim)
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 36, Me.txtUsername.Tag.ToString.Trim)
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, DateTime.Now.ToString())
        cmd.Parameters.Append(pa)
        Dim strLastId As String = System.Guid.NewGuid.ToString("D")
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 36, strLastId)
        cmd.Parameters.Append(pa)

        cmd.CommandText = sb.ToString()
        cmd.CommandType = ADODB.CommandTypeEnum.adCmdText
        If ct.ExcCommand(cmd) Then
            '更新关联数据
            InsertCrashInOut(Me.txt冲账关联1.Tag.ToString, Me.NM冲账关联金额1.Value, strLastId)
            InsertCrashInOut(Me.txt冲账关联2.Tag.ToString, Me.NM冲账关联金额2.Value, strLastId)
            InsertCrashInOut(Me.txt冲账关联3.Tag.ToString, Me.NM冲账关联金额3.Value, strLastId)
            InsertCrashInOut(Me.txt冲账关联4.Tag.ToString, Me.NM冲账关联金额4.Value, strLastId)
            '
            '插入金额 2022-11-20
            Account_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txtUsername.Tag.ToString.Trim, numUpDown.Value)

            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联1.Tag.ToString, Me.NM冲账关联金额1.Value)
            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联2.Tag.ToString, Me.NM冲账关联金额2.Value)
            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联3.Tag.ToString, Me.NM冲账关联金额3.Value)
            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联4.Tag.ToString, Me.NM冲账关联金额4.Value)

            Me.bAdd = True '表示成功插入数据能刷新界面        
            ShowMessageBox("插入成功")
            ClearForm()
            DoInsert = True
        Else
            DoInsert = False
        End If
    End Function

#Region "更新模式"

    Private Sub InsertCrashInOut(ByVal 状态ID As String, ByVal 冲账金额 As Decimal, ByVal 冲账ID As String)

        If 状态ID <> "" AndAlso 冲账金额 > 0 Then
            Dim sb As New StringBuilder
            Dim cmd As ADODB.Command = New ADODB.Command
            sb.Length = 0
            sb.AppendLine("Update CrashStatus set Count=Count -" & 冲账金额.ToString & " Where id='" & 状态ID.ToString & "'")
            cmd.CommandText = sb.ToString
            ct.ExcCommand(cmd)
            UpdateCrashOptime(ct, 状态ID.ToString)

            sb.Length = 0
            Dim pa As ADODB.Parameter = cmd.CreateParameter(, ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 36, System.Guid.NewGuid.ToString("D"))
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 36, 冲账ID)
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adChar, ADODB.ParameterDirectionEnum.adParamInput, 36, 状态ID)
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDecimal, ADODB.ParameterDirectionEnum.adParamInput)
            pa.Value = 冲账金额
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, DateTime.Now.ToString())
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 36, Me.txtUsername.Tag.ToString.Trim)
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, Me.txtMemo.Text.Trim)
            cmd.Parameters.Append(pa)

            pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, dt1.Value.ToString)
            cmd.Parameters.Append(pa)

            sb.AppendLine("Insert into CrashInOut values(?,?,?,?,?,6,?,?,?,' ')")

            cmd.CommandText = sb.ToString
            ct.ExcCommand(cmd)
        End If

    End Sub

    Private Sub UpdateCrashInOut()
        Dim sb As New StringBuilder
        Dim dt As New DataTable
        Dim rs As ADODB.Recordset = ct.GetTable("SELECT * from CrashInOut  where InOutID='" + CStr(Me.参数列表("ID")) + "'")
        dt = ct.FillTable(rs)
        If dt.Rows.Count > 0 Then
            Dim cmdSub As ADODB.Command = New ADODB.Command
            cmdSub.CommandType = ADODB.CommandTypeEnum.adCmdText
            For Each dr As DataRow In dt.Rows
                If CStr(dr("CrashStatusID")) <> "" AndAlso CDec(dr("CrashStatusCount")) > 0 Then
                    sb.Length = 0
                    sb.AppendLine("Update CrashStatus set Count=Count +" & CStr(dr("CrashStatusCount")) & " Where id='" & CStr(dr("CrashStatusID")) + "'")
                    cmdSub.CommandText = sb.ToString
                    ct.ExcCommand(cmdSub)
                    UpdateCrashOptime(ct, CStr(dr("CrashStatusID")))

                    '2011-11-20
                    Account_Detail.Update冲账_减(ct, CDate(dr("DATETIME")).ToString("yyyy-MM-dd"), dr("USERNAME").ToString, CDec(dr("CrashStatusCount")))
                    Crash_Detail.Update冲账_减(ct, CDate(dr("DATETIME")).ToString("yyyy-MM-dd"), dr("CrashStatusID").ToString, CDec(dr("CrashStatusCount")))

                End If
            Next
        End If
        ct.GetTable("DELETE from CrashInOut  where InOutID='" + CStr(Me.参数列表("ID")) + "'")
    End Sub

    Public Overrides Function DoUpdate() As Boolean
        MyBase.DoUpdate()
        DoUpdate = False
        Dim sb As New StringBuilder
        Dim cmd As New ADODB.Command
        sb.Length = 0

        UpdateCrashInOut()

        sb.AppendLine(" UPDATE ")
        sb.AppendLine(" CrashToCrash ")
        sb.AppendLine(" SET ")
        sb.AppendLine("  Title=? ")
        sb.AppendLine(" ,Count=? ")
        sb.AppendLine(" ,DateTime=? ")
        sb.AppendLine(" ,Memo=? ")
        sb.AppendLine(" ,UserName=? ")
        sb.AppendLine(" ,OPTIME=? ")
        sb.AppendLine("  WHERE  ")
        sb.AppendLine("  ID=? ")

        Dim pa As ADODB.Parameter
        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adVarWChar, ADODB.ParameterDirectionEnum.adParamInput)
        If CMainModule.CmnToStr1(Me.txtTitle.Text).Trim().Length > 0 Then
            pa.Size = CMainModule.CmnToStr1(Me.txtTitle.Text).Trim().Length
        Else
            pa.Size = 10
        End If
        pa.Value = CMainModule.CmnToStr1(Me.txtTitle.Text).Trim()
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDecimal, ADODB.ParameterDirectionEnum.adParamInput)
        pa.Value = numUpDown.Value
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, dt1.Value.ToString)
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 100, Me.txtMemo.Text.Trim)
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 36, Me.txtUsername.Tag.ToString.Trim)
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adDBTimeStamp, ADODB.ParameterDirectionEnum.adParamInput, 100, DateTime.Now.ToString())
        cmd.Parameters.Append(pa)

        pa = cmd.CreateParameter(, ADODB.DataTypeEnum.adWChar, ADODB.ParameterDirectionEnum.adParamInput, 36, CStr(Me.参数列表("ID")))
        cmd.Parameters.Append(pa)

        cmd.CommandText = sb.ToString()
        If (ct.ExcCommand(cmd)) Then
            '更新关联数据
            InsertCrashInOut(Me.txt冲账关联1.Tag.ToString, Me.NM冲账关联金额1.Value, CStr(Me.参数列表("ID")))
            InsertCrashInOut(Me.txt冲账关联2.Tag.ToString, Me.NM冲账关联金额2.Value, CStr(Me.参数列表("ID")))
            InsertCrashInOut(Me.txt冲账关联3.Tag.ToString, Me.NM冲账关联金额3.Value, CStr(Me.参数列表("ID")))
            InsertCrashInOut(Me.txt冲账关联4.Tag.ToString, Me.NM冲账关联金额4.Value, CStr(Me.参数列表("ID")))

            '插入金额 2022-11-20
            Account_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txtUsername.Tag.ToString.Trim, numUpDown.Value)

            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联1.Tag.ToString, Me.NM冲账关联金额1.Value)
            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联2.Tag.ToString, Me.NM冲账关联金额2.Value)
            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联3.Tag.ToString, Me.NM冲账关联金额3.Value)
            Crash_Detail.Update冲账_加(ct, dt1.Value.ToString("yyyy-MM-dd"), Me.txt冲账关联4.Tag.ToString, Me.NM冲账关联金额4.Value)

            ShowMessageBox("更新成功")
            bAdd = True
            Me.Close()
        Else
            ShowMessageBox("更新失败")
        End If
        DoUpdate = True
    End Function

    Public Overrides Function DoUpdateCheck() As Boolean
        MyBase.DoUpdateCheck()
        DoUpdateCheck = False
        Me.ValidateChildren()
        If Me.txtTitle.Text.Trim = String.Empty Then
            ShowMessageBox("冲账原因不能为空")
            Me.txtTitle.Focus()
            Exit Function
        End If

        'If numUpDown.Value <= 0 Then
        '    ShowMessageBox("冲账不能小于0")
        '    Me.numUpDown.Focus()
        '    Exit Function
        'End If

        If Me.txtUsername.Text.Trim = String.Empty Then
            ShowMessageBox("冲账用户不能为空")
            Me.btnUsername.Focus()
            Exit Function
        End If

        If chk是否启用关联更新.Checked Then
            If numUpDown.Value <> Me.NM冲账关联金额1.Value + Me.NM冲账关联金额2.Value + Me.NM冲账关联金额3.Value + Me.NM冲账关联金额4.Value Then
                If ShowMessageResult("关联金额与冲账金额不相等,是否继续？") = Windows.Forms.DialogResult.No Then
                    Me.NM冲账关联金额1.Focus()
                    Exit Function
                End If
            End If
        End If

        DoUpdateCheck = True
    End Function

    Public Overrides Function DoUpdateExist() As Boolean
        DoUpdateExist = False
        MyBase.DoUpdateExist()
        If CStr(Me.参数列表("ID")).Trim = "" Then
            ShowMessageBox("没有选择任何记录")
            Exit Function
        End If
        DoUpdateExist = True
    End Function

    Public Overrides Sub InitUpdate()
        MyBase.InitUpdate()
        Me.Text = "冲账更新"

        Dim rs As ADODB.Recordset = Nothing
        Dim sb As New StringBuilder
        sb.AppendLine(" select CrashToCrash.*,WysInputUser.UserName as UserName1")
        sb.AppendLine("  from CrashToCrash ")
        sb.AppendLine("left join WysInputUser on WysInputUser.id =CrashToCrash.username  WHERE CrashToCrash.id='" + CStr(Me.参数列表("ID")) + "'")
        rs = ct.GetTable(sb.ToString)

        If rs IsNot Nothing Then
            If rs.EOF = False Then
                Me.txtTitle.Text = CMainModule.CmnToStr(rs.Fields("Title").Value)
                Me.dt1.Text = CMainModule.CmnToStr(rs.Fields("DateTime").Value)
                Me.txtMemo.Text = CMainModule.CmnToStr(rs.Fields("Memo").Value)
                Me.numUpDown.Text = CDec(rs.Fields("Count").Value)
                Me.txtUsername.Text = UTIL.CUtil.ConvertText(rs.Fields("UserName1").Value)
                Me.txtUsername.Tag = UTIL.CUtil.ConvertText(rs.Fields("UserName").Value)

                Dim dt As New DataTable
                Dim rs1 As ADODB.Recordset = ct.GetTable("SELECT CrashInOut.*, CrashStatus.TITLE from CrashInOut left join CrashStatus on CrashStatus.ID=CrashInOut.CrashStatusID where InOutID='" + CStr(Me.参数列表("ID")) + "'")
                dt = ct.FillTable(rs1)

                If dt.Rows.Count > 0 Then
                    Me.txt冲账关联1.Text = UTIL.CUtil.ConvertText(dt.Rows(0)("Title"))
                    Me.txt冲账关联1.Tag = UTIL.CUtil.ConvertText(dt.Rows(0)("CrashStatusID"))
                    Me.NM冲账关联金额1.Value = CDec(dt.Rows(0)("CrashStatusCount"))
                End If

                If dt.Rows.Count > 1 Then
                    Me.txt冲账关联2.Text = UTIL.CUtil.ConvertText(dt.Rows(1)("Title"))
                    Me.txt冲账关联2.Tag = UTIL.CUtil.ConvertText(dt.Rows(1)("CrashStatusID"))
                    Me.NM冲账关联金额2.Value = CDec(dt.Rows(1)("CrashStatusCount"))
                End If

                If dt.Rows.Count > 2 Then
                    Me.txt冲账关联3.Text = UTIL.CUtil.ConvertText(dt.Rows(2)("Title"))
                    Me.txt冲账关联3.Tag = UTIL.CUtil.ConvertText(dt.Rows(2)("CrashStatusID"))
                    Me.NM冲账关联金额3.Value = CDec(dt.Rows(2)("CrashStatusCount"))
                End If

                If dt.Rows.Count > 3 Then
                    Me.txt冲账关联4.Text = UTIL.CUtil.ConvertText(dt.Rows(3)("Title"))
                    Me.txt冲账关联4.Tag = UTIL.CUtil.ConvertText(dt.Rows(3)("CrashStatusID"))
                    Me.NM冲账关联金额4.Value = CDec(dt.Rows(3)("CrashStatusCount"))
                End If
            End If
            rs.Close()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
        End If
        rs = Nothing
    End Sub

#End Region

    Private Sub btnUsername_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUsername.Click
        Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
            frm.Text = "冲账人一览"
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = "select ID,username as 名称,memo as 备注 from WysInputUser  where type=0 order by 名称"
            Dim 显示列 As New StringCollection
            显示列.Add("名称")
            显示列.Add("备注")
            frm.Width = 250
            frm.Height = 200
            frm.显示列 = 显示列
            frm.ShowDialog()
            If frm.返回值.Count > 0 Then
                txtUsername.Tag = CStr(frm.返回值(0))
                txtUsername.Text = CStr(frm.返回值(1))
            End If
        End Using
    End Sub

    Private Sub btn冲账关联_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn冲账关联1.Click, btn冲账关联2.Click, btn冲账关联4.Click, btn冲账关联3.Click
        Using frm As Wys.Control.Vb.ListForm = New Wys.Control.Vb.ListForm
            frm.Text = "冲账账户一览"
            frm.strName = Me.strName
            frm.iType = Me.iType
            frm.SQL = "select ID,TITLE as 名称,Count as 金额,MEMO AS 备注 from CrashStatus where id= '59bb7afa-a44f-411e-9470-e2b47d43e94c' order by 名称"
            Dim 显示列 As New StringCollection
            显示列.Add("名称")
            显示列.Add("金额")
            显示列.Add("备注")
            frm.Width = 300
            frm.Height = 300
            frm.显示列 = 显示列
            frm.ShowDialog()
            If frm.返回值.Count > 0 Then
                If CType(sender, Button) Is Me.btn冲账关联1 Then
                    txt冲账关联1.Tag = CStr(frm.返回值(0))
                    txt冲账关联1.Text = CStr(frm.返回值(1))
                    NM冲账关联金额1.Value = numUpDown.Value - NM冲账关联金额2.Value - NM冲账关联金额3.Value - NM冲账关联金额4.Value
                ElseIf CType(sender, Button) Is Me.btn冲账关联2 Then
                    txt冲账关联2.Tag = CStr(frm.返回值(0))
                    txt冲账关联2.Text = CStr(frm.返回值(1))
                    NM冲账关联金额2.Value = numUpDown.Value - NM冲账关联金额1.Value - NM冲账关联金额3.Value - NM冲账关联金额4.Value
                ElseIf CType(sender, Button) Is Me.btn冲账关联3 Then
                    txt冲账关联3.Tag = CStr(frm.返回值(0))
                    txt冲账关联3.Text = CStr(frm.返回值(1))
                    NM冲账关联金额3.Value = numUpDown.Value - NM冲账关联金额1.Value - NM冲账关联金额2.Value - NM冲账关联金额4.Value
                ElseIf CType(sender, Button) Is Me.btn冲账关联4 Then
                    txt冲账关联4.Tag = CStr(frm.返回值(0))
                    txt冲账关联4.Text = CStr(frm.返回值(1))
                    NM冲账关联金额4.Value = numUpDown.Value - NM冲账关联金额1.Value - NM冲账关联金额2.Value - NM冲账关联金额3.Value
                End If

            End If
        End Using
    End Sub

    Private Sub NM冲账关联金额1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles NM冲账关联金额1.Validating, NM冲账关联金额4.Validating, NM冲账关联金额3.Validating, NM冲账关联金额2.Validating
        If CType(sender, NumericUpDown) Is Me.NM冲账关联金额1 Then
            If Me.NM冲账关联金额1.Value = 0 Then
                Me.txt冲账关联1.Tag = ""
                Me.txt冲账关联1.Text = ""
            End If
            If Me.txt冲账关联1.Tag.ToString = "" Then
                Me.NM冲账关联金额1.Value = 0
            End If
        ElseIf CType(sender, NumericUpDown) Is Me.NM冲账关联金额2 Then
            If Me.NM冲账关联金额2.Value = 0 Then
                Me.txt冲账关联2.Tag = ""
                Me.txt冲账关联2.Text = ""
            End If
            If Me.txt冲账关联2.Tag.ToString = "" Then
                Me.NM冲账关联金额2.Value = 0
            End If
        ElseIf CType(sender, NumericUpDown) Is Me.NM冲账关联金额3 Then
            If Me.NM冲账关联金额3.Value = 0 Then
                Me.txt冲账关联3.Tag = ""
                Me.txt冲账关联3.Text = ""
            End If
            If Me.txt冲账关联3.Tag.ToString = "" Then
                Me.NM冲账关联金额3.Value = 0
            End If
        ElseIf CType(sender, NumericUpDown) Is Me.NM冲账关联金额4 Then
            If Me.NM冲账关联金额4.Value = 0 Then
                Me.txt冲账关联4.Tag = ""
                Me.txt冲账关联4.Text = ""
            End If
            If Me.txt冲账关联4.Tag.ToString = "" Then
                Me.NM冲账关联金额4.Value = 0
            End If
        End If
    End Sub

    Private Sub chk是否启用关联更新_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk是否启用关联更新.Click
        If Not Me.chk是否启用关联更新.Checked Then
            Me.NM冲账关联金额1.Enabled = False
            Me.btn冲账关联1.Enabled = False
            Me.txt冲账关联1.Text = ""
            Me.txt冲账关联1.Tag = ""
            Me.NM冲账关联金额1.Value = 0

            Me.NM冲账关联金额2.Enabled = False
            Me.btn冲账关联2.Enabled = False
            Me.txt冲账关联2.Text = ""
            Me.txt冲账关联2.Tag = ""
            Me.NM冲账关联金额2.Value = 0

            Me.NM冲账关联金额3.Enabled = False
            Me.btn冲账关联3.Enabled = False
            Me.txt冲账关联3.Text = ""
            Me.txt冲账关联3.Tag = ""
            Me.NM冲账关联金额3.Value = 0

            Me.NM冲账关联金额4.Enabled = False
            Me.btn冲账关联4.Enabled = False
            Me.txt冲账关联4.Text = ""
            Me.txt冲账关联4.Tag = ""
            Me.NM冲账关联金额4.Value = 0
        Else
            Me.NM冲账关联金额1.Enabled = True
            Me.btn冲账关联1.Enabled = True

            Me.NM冲账关联金额1.Enabled = True
            Me.btn冲账关联2.Enabled = True

            Me.NM冲账关联金额3.Enabled = True
            Me.btn冲账关联3.Enabled = True

            Me.NM冲账关联金额4.Enabled = True
            Me.btn冲账关联4.Enabled = True
        End If
    End Sub

    Private Sub CrashToCrash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class